package com.itheima.mapper;

import com.itheima.pojo.Classes;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

/**
 * The interface Classes mapper.
 */
@Mapper
public interface ClassesMapper {


    /**
     * 新增班级
     *
     * @param classes the classes
     */
    void addClass(Classes classes);

    /**
     * 通过分页进行查询
     *
     * @param name  the name
     * @param begin the start time
     * @param end   the end time
     * @return the list
     */
    List<Classes> selectClassesByPage(String name, LocalDate begin, LocalDate end);

    /**
     * 根据id删除班级
     *
     * @param id the id
     */
    @Delete("delete from classes where id = #{id}")
    void deleteClassById(@Param("id") Integer id);

    /**
     * 根据id查询班级信息
     *
     * @param id the id
     * @return the classes
     */
    @Select("select * from classes where id = #{id};")
    Classes selectClassById(Integer id);

    /**
     * 根据id修改班级信息
     *
     * @param classes the classes
     */
    void updateClassById(Classes classes);

    /**
     * 通过班级名称查询班级名称是否重复
     *
     * @param name the name
     * @return the integer
     */
    @Select("select count(*) from classes where name = #{name}")
    Integer selectCountByName(String name);

    /**
     * 通过班级名称查询班级名称是否重复并且排除自身的干扰
     *
     * @param name the name
     * @param id   the id
     * @return the integer
     */
    @Select("select count(*) from classes where name = #{name} and id != #{id}")
    Integer selectCountByNameNotId(String name, Integer id);
}
